<template>
  <el-row :gutter="24">
    <el-col :span="6" class="boxs box1" v-for="item in list" :key="item">
      <div class="listTh">个人信息</div>
      <div class="styImg">
        <img src="@/assets/logo.png" />
      </div>
      <el-row :gutter="20">
        <el-col :span="12">
          <template><i class="el-icon-user"></i> 用户名称</template>
        </el-col>
        <span>{{ item.user }}</span>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <template> <i class="el-icon-mobile-phone"></i> 手机号码</template>
        </el-col>
        <span>{{ item.callNumber }}</span>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <template> <i class="el-icon-message"></i> 用户邮箱</template>
        </el-col>
        <span>{{ item.usEmail }}</span>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <template><i class="el-icon-share"></i> 所属部门</template>
        </el-col>
        <span> {{ item.branch }}</span>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <template><i class="el-icon-service"></i> 创建角色</template>
        </el-col>
        <span>{{ item.role }}</span>
      </el-row>
    </el-col>

    <el-col :span="17" class="boxs">
      <div class="grid-content bg-purple">
        <div class="listTh">基本资料</div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="基本资料" name="first">
            <el-form
              :model="ruleForm"
              :rules="rules"
              ref="ruleForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item label="用户昵称" prop="name">
                <el-input v-model="ruleForm.name"></el-input>
              </el-form-item>
              <el-form-item label="手机号码" prop="number">
                <el-input v-model="ruleForm.number"></el-input>
              </el-form-item>
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="ruleForm.email"></el-input>
              </el-form-item>
              <el-form-item label="性别" prop="resource">
                <el-radio-group v-model="ruleForm.resource">
                  <el-radio label="男"></el-radio>
                  <el-radio label="女"></el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')"
                  >保存</el-button
                >
                <el-button @click="resetForm('ruleForm')" id="shut"
                  >关闭</el-button
                >
              </el-form-item>
            </el-form>
          </el-tab-pane>

          <el-tab-pane label="修改密码" name="second">
            <el-form
              :model="ruleForm"
              status-icon
              :rules="rules"
              ref="ruleForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item label="旧密码" prop="wordpass">
                <el-input
                  type="password"
                  v-model="ruleForm.pass"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="新密码" prop="newpass">
                <el-input
                  type="password"
                  v-model="ruleForm.pass"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item label="确认密码" prop="checkPass">
                <el-input
                  type="password"
                  v-model="ruleForm.checkPass"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')"
                  >保存</el-button
                >
                <el-button @click="resetForm('ruleForm')">关闭</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-col>
    <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
  </el-row>
</template>

<script>
export default {
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (value < 18) {
            callback(new Error("必须年满18岁"));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      list: [
        {
          user: "admin",
          nickname: "四尾",
          callNumber: "13756485544",
          usEmail: "tbyzlqffzy@qq.com",
          branch: "四尾",
          role: "admin",
        },
      ],

      activeName: "first",
      tableData: [
        {
          date: "2016-05-03",
        },
      ],
      ruleForm: {
        name: "",
        number: "",
        email: "",
        type: [],
        wornpass: "",
        newPass: "",
        checkPass: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入用户昵称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        number: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            type: "text",
            message: "请输入正确的手机号",
            trigger: ["blur", "change"],
          },
        ],
        email: [
          { required: true, message: "请输入邮箱地址", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  computed: {
    Time() {
      return new Date().toLocaleString();
    },
  },
  methods: {
    handleClick(tab, event) {},
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("保存成功");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./scss/index.scss";
</style>